<?php
class Admin_LoginController extends Australian_Controller_Action {
	
	// Mang tham so nhan duoc o moi Action
	protected $_arrParam;
	
	// Duong dan cua Controller
	protected $_currentController;
	
	// Duong dan cua Action chinh
	protected $_actionMain;
	
	public function init(){
		
		// Mang tham so nhan duoc o moi Action
		$this->_arrParam = $this->_request->getParams();
		
		// Duong dan cua Controller
		$this->_currentController = '/' . $this->_arrParam['module']
		. '/' . $this->_arrParam['controller'];
		
		// Duong dan cua Action chinh
		$this->_actionMain = '/' . $this->_arrParam['module']
		. '/' . $this->_arrParam['controller'] . '/index';
		
		// Truyen ra view
		$this->view->arrParam = $this->_arrParam;
		$this->view->currentController = $this->_currentController;
		$this->view->actionMain = $this->_actionMain;
		
		parent::init();
		$template_path = TEMPLATE_PATH . "/admin/login";
		$this->loadTemplate($template_path, 'template.ini', 'template');
	}
	
	public function indexAction(){
		if($this->_request->isPost()){
// 			$error = 'Username and Password not empty!';
// 			if($this->_arrParam['username'] == '' AND $this->_arrParam['password'] == ''){
// 				$this->view->Not = '<div class="error-box round">' . $error . '</div>';
// 			}
// Kiem tra valiadate form o day

			$auth = new Australian_System_Auth();
			$error = 'Username or password invalid, please try again!';
			if($auth->login($this->_arrParam) == true){
                                $controller = $auth->getPage();
				$this->_helper->redirector('index', $controller);
			}else{
				//$error[] = $auth->getError();
				$this->view->Not = '<div class="error-box round">' . $error . '</div>';
			}
		}
	}
	
	public function logoutAction(){
		$auth = new Australian_System_Auth();
		$auth->logout();
		
		$this->_helper->redirector('index', 'login');
		$this->_helper->viewRenderer->setNoRender();
		
		
	}
}
